import type { Ref } from 'vue'

export function useStorage(name: Ref<string>) {
  return {
    get value() {
      return JSON.parse(localStorage.getItem(name.value))
    },
    set value(value) {
      if (value === null) {
        localStorage.removeItem(name.value)
      } else {
        localStorage.setItem(name.value, JSON.stringify(value))
      }
    },
  }
}
